package com.hxh.generater.springBoot.springboot3_vue3.gen;


import com.hxh.entity.Project;
import com.hxh.generater.springBoot.genBase.InitBaseProject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description: 初始化springboot3+vue3项目方法  通过反射,动态调用
 * @Author: HXH
 */
@Slf4j
public class InitSb3Vue3BaseProject extends InitBaseProject {
    /**
     * @param project
     * @return void
     * @author HXH
     * @description: 初始化数据库相关
     * @date 2024/5/21
     */
    @Override
    public void initDatabaseData(Project project) throws Exception {
        new InitSb3Vue3Sql().createTablesAndInitData(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 初始化菜单相关
     * @date 2024/5/21
     **/
    @Override
    public void initMenu(Project project) throws Exception {
        //放数据库管理了
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 初始化缓存相关
     * @date 2024/5/21
     **/
    @Override
    public void initCache(Project project) throws Exception {
        new GenSb3Vue3Cache().generationLocalCache(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 登录/权限相关
     * @date 2024/5/21
     **/
    @Override
    public void initLoginAndPermissions(Project project) throws Exception {
        GenSb3Vue3LoginAndPermission genSb3Vue3LoginAndPermission = new GenSb3Vue3LoginAndPermission();
        genSb3Vue3LoginAndPermission.generationLoginAbout(project, null, null, null);
        genSb3Vue3LoginAndPermission.generationKaptchaConfiguration(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 系统日志相关
     * @date 2024/5/21
     **/
    @Override
    public void initSystemLog(Project project) throws Exception {

    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 初始化工具类
     * @date 2024/5/21
     **/
    @Override
    public void initSystemUtils(Project project) throws Exception {
        new GenSb3Vue3Util().generationUtils(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 初始化系统配置类 如跨域等
     * @date 2024/5/21
     **/
    @Override
    public void initSystemConfig(Project project) throws Exception {
        GenSb3Vue3SystemConfig genSb3Vue3SystemConfig = new GenSb3Vue3SystemConfig();
        genSb3Vue3SystemConfig.generationConfigAbout(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description: 初始化系统基础代码，如pom.xml，application、yml等
     * @date 2024/5/21
     **/
    @Override
    public void initSystemBase(Project project) throws Exception {
        GenSb3Vue3SystemBase genSb3Vue3SystemBase = new GenSb3Vue3SystemBase();
        genSb3Vue3SystemBase.generationSystemBase(project);
    }

    /**
     * @param project :
     * @return void
     * @author HXH
     * @description:
     * @date 2024/5/21 创建数据库中所有表的crud
     **/
    @Override
    public void initAllTableCRUD(Project project, boolean initExtendTable) throws Exception {
        try {
            new GenSb3Vue3TableCRUD().generationAllTableCRUD(project, initExtendTable);
        } catch (Exception e) {
            log.error("创建数据库中所有表的crud异常", e);
            throw e;
        }
    }

    /**
     * 不同模板特有的东西，如果有需要可以添加实现
     *
     * @param project
     */
    @Override
    public void initCustom(Project project) throws Exception {

    }

    /**
     * @param project
     * @return void
     * @author HXH
     * @description: 可选组件
     * @date 2024/5/21
     */
    @Override
    public void initAddition(Project project) throws Exception {
        String component = project.getAdditionComponent();
        if (StringUtils.isBlank(component)) {
            return;
        }
        List<String> componentList = new ArrayList<>(Arrays.asList(component.split(",")));
        if (componentList.contains("redis")) {
            //redis组件
            GenSb3Vue3Addition.processRedisMaven(project);
            GenSb3Vue3Addition.generationRedisCacheClass(project);
            GenSb3Vue3Addition.generationApplicationDevYmlForRedis(project);
        }
        if (componentList.contains("mongo")) {
            //mongo
            GenSb3Vue3Addition.processMongoMaven(project);
            GenSb3Vue3Addition.generationMongoCacheClass(project);
            GenSb3Vue3Addition.generationApplicationDevYmlForMongo(project);
        }

    }
}
